<?php
		$localControlKey = $this->item->getLocalControlKey();
		$thisReserveId = ($this->reserve ? $this->reserve->getReserveId() : '');
?>
<div class="headingCell1">TITLE (<?php print($localControlKey); ?>)</div>
<div class="headingSection">
<div id="item_title" style="padding:8px 8px 12px 8px;">
<h3>Reserve Items with this Control Key</h3>
<ul>
<?php 
	$matchingItems = $this->item->getMathcingItemsBy('local_control_key');
	foreach($matchingItems as $localControlKeyMatch){
?> 
	<li>(Reserve ID: <?php print($localControlKeyMatch->getReserveId()); ?>, ItemID: <?php print($localControlKeyMatch->getItemId()); ?>)
		<?php if ($thisReserveId == $localControlKeyMatch->getReserveId()) {?>
		<b>Currently Selected Item</b>
		<?php } ?>
		<br/>
		<?php 
		?>
		<?php if ($thisReserveId != $localControlKeyMatch->getReserveId()) {?>
		<a href="?cmd=editItem&tab=status&reserveID=<?php print($localControlKeyMatch->getReserveId()); ?>">
		<?php } ?>
		<?php print('' != trim($localControlKeyMatch->getVolumeTitle()) ? ('<i>' . $localControlKeyMatch->getVolumeTitle() . '</i>, ') : '');
		print($localControlKeyMatch->getTitle()); ?>
		<?php if ($thisReserveId != $localControlKeyMatch->getReserveId()) {?></a> <?php } ?>,
		
		<?php print('' != trim($localControlKeyMatch->getVolumeEdition()) ? ($localControlKeyMatch->getVolumeEdition() . ', ') : ''); ?>
		<?php print('' != trim($localControlKeyMatch->getSource()) ? ($localControlKeyMatch->getSource() . ', ') : ''); ?>
		<?php print('' != trim($localControlKeyMatch->getPagesTimes()) ? ($localControlKeyMatch->getPagesTimes() . ', ') : ''); ?>
		<b>For: </b>
		<?php if('' != $localControlKeyMatch->getReserveId()) { 
			$course = $localControlKeyMatch->getCourseInstance();
			$primaryCourse = $course->getPrimaryCourse();
			$primaryDepartment = $primaryCourse->getDepartment();
			?>
		
			<a href="?cmd=editClass&ci=<?php print($course->getCourseInstanceID()); ?>">
			<?php print($course->getTerm()); ?> <?php print($course->getYear()); ?> 
			<?php print($primaryDepartment); ?> <?php print($primaryCourse->getCourseNo()); ?> <?php print($primaryCourse->getSection()); ?>
			</a>
		<?php } else { ?>
			<i>Not properly associated with a course.</i>
		<?php } ?></li>
<?php 
	}
?>
</ul>
<?php 
if ($this->ils->supportsItemLookup()) {
?>
<h3><?php print($this->ils->getName()); ?>'s Current Information on <?php print($localControlKey); ?></h3>
<?php 
	//#TODO this it totally not the right place to handle this...
	try{
		$ilsResult = $this->ils->search('controlKey',$localControlKey);
		$ilsHasNoTitles = 0 == $ilsResult->getTitleCount();
	} catch (Exception $e) {
		$ilsHasNoTitles = true;	
	}
	if (!$ilsHasNoTitles) {
?>	<div class="ilsInfo">
		<p>Found <?php print($ilsResult->getTitleCount()); ?> title, <?php print($ilsResult->getHoldingCount()); ?> holding<?php if($ilsResult->getHoldingCount() != 1) {?>s<?php } ?>.</p>
		<p><b>Title:</b> <?php print($ilsResult->getTitle()); ?></p>
		<p class="noMarginBottom"><b>Holdings:</b></p>
		<ul>
		<?php foreach ($ilsResult->getHoldings() as $holding) { /*TODO this should be called in the manager... */ ?>
			<li><?php print(
				(
					array_key_exists('library',$holding) 
					? "Library: {$holding['library']} "
					: ''
				) . (
					array_key_exists('loc',$holding) 
					? "Location: {$holding['loc']} "
					: ''
				) . (
					array_key_exists('callNum',$holding) 
					? "Call Number: {$holding['callNum']} "
					: ''
				) . (
					array_key_exists('type',$holding) 
					? "Type: {$holding['type']} "
					: ''
				)
			);?></li>
		<?php } ?>
		</ul>
	</div>

<?php }
}
 if ('' != $localControlKey) { ?>
<?php $this->getDisplayer()->displayQuickviewLink($localControlKey, 'View this title in the catalog.'); ?>
<?php } else { ?>
<p class="warning">This item's control number does not match the expected format.</p>
<?php } ?>
</div></div>
<div class="headingCell1">PHYSICAL COPIES</div>
<div class="headingSection">
<div id="item_title" style="padding:8px 8px 12px 8px;">
<h3>Barcodes associated with this Catkey</h3>
<ul>
<?php 
	$physicalCopies = array();
	foreach($matchingItems as $localControlKeyMatch){
		$itemPhysicalCopies = $localControlKeyMatch->getPhysicalCopies();
		foreach($itemPhysicalCopies as $physicalCopy){
			$physicalCopies[$physicalCopy->getPhysicalCopyID()] = $physicalCopy;
		}
	}
	$barcodesAllSucceed = true;
	$anyBarcodeSucceeds = false;
	foreach($physicalCopies as $physicalCopy){
?>
		<li>(UID: <?php print($physicalCopy->getItemId()); ?>)<br/>
		<?php print($physicalCopy->getBarcode()); ?>,
<?php 
		$barcodeResult = $this->ils->barcodeLookup($physicalCopy->getBarcode());
		$barcodeTitleLocalControlKey = $barcodeResult['local_control_key'];
?>
		<?php print(
			$barcodeTitleLocalControlKey == $localControlKey
			? ('Local Control Key: ' . $barcodeTitleLocalControlKey)
			: '<span class="warning">Local Control Key Mismatch: ' . $barcodeTitleLocalControlKey . ' </warning>'
		);?>
		</li>
<?php 
	}

?>
</ul>
<?php if ('' != $localControlKey && $ilsHasNoTitles) { ?>
	<p class="warning">This title appears to be fully shadowed (shadowed at the title level, or all items are shadowed) in the ILS!</p>
<?php } ?>
</div></div>